package cn.da.shuai.cool.system.api.controller;

import cn.da.shuai.cool.common.entity.R;
import cn.da.shuai.cool.system.model.entity.job.CoolJobLog;
import cn.da.shuai.cool.system.service.service.ICoolJobLogService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 调度日志操作处理
 */
@RestController
@RequestMapping("/monitor/jobLog")
@Tag(name = "定时任务日志控制器")
public class CoolJobLogController {

    @Autowired
    private ICoolJobLogService jobLogService;

    @GetMapping("/list")
    @Operation(summary = "获取定时任务调度日志列表")
    public R<List<CoolJobLog>> list(CoolJobLog jobLog) {
        List<CoolJobLog> list = jobLogService.selectJobLogList(jobLog);
        return R.ok(list);
    }

    @GetMapping("/page")
    @Operation(summary = "获取定时任务调度日志分页列表")
    public R<Page<CoolJobLog>> page(CoolJobLog jobLog, Page<CoolJobLog> page) {
        Page<CoolJobLog> list = jobLogService.selectJobLogPage(jobLog, page);
        return R.ok(list);
    }

    @GetMapping("/{jobLogId}")
    @Operation(summary = "根据调度编号获取详细信息")
    public R<CoolJobLog> getInfo(@PathVariable Long jobLogId) {
        return R.ok(jobLogService.selectJobLogById(jobLogId));
    }

    @DeleteMapping("/{jobLogIds}")
    @Operation(summary = "删除定时任务调度日志")
    public R<Void> remove(@PathVariable Long[] jobLogIds) {
        jobLogService.deleteJobLogByIds(jobLogIds);
        return R.ok();
    }

    @DeleteMapping("/clean")
    @Operation(summary = "清空定时任务调度日志")
    public R<Void> clean() {
        jobLogService.cleanJobLog();
        return R.ok();
    }
}